import 'package:eplorex/pages/activity/activity_tab_list_page.dart';
import 'package:flutter/material.dart';

import '../../models/activity/common_tab_title_model.dart';
import 'activity_tab_page.dart';

class ActivityPage extends StatefulWidget {
  @override
  State<ActivityPage> createState() => _ActivityPageState();
}

class _ActivityPageState extends State<ActivityPage>
    with TickerProviderStateMixin {
  late TabController _controller;
  List<CommonTabTitle> tabs = [];
  List<Widget> _tabPages = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = TabController(length: 4, vsync: this);
    _tabPages = [ActivityTabListPage(), ActivityTabPage(), ActivityTabPage()];
    _loadData();
  }

  //初始化tab数据
  void _loadData() async {
    _controller = TabController(length: 0, vsync: this);
    tabs.add(CommonTabTitle(labelName: "活动", groupChannelCode: "11", type: 1));
    tabs.add(CommonTabTitle(labelName: "小众", groupChannelCode: "11", type: 1));
    tabs.add(CommonTabTitle(labelName: "攻略", groupChannelCode: "11", type: 1));
    try {
      _controller =
          TabController(length: tabs.length, vsync: this); // fix tab label 空白问题
      setState(() {});
    } catch (e) {
      print(e);
    }
  }

  @override
  void dispose() {
    // TODO: implement dispose
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: null,
        title: Text("发现"),
      ),
      body: Column(
        children: [
          Container(
            color: Colors.white,
            child: TabBar(
              controller: _controller,
              labelStyle: TextStyle(fontSize: 18),
              isScrollable: true,
              labelColor: Colors.black,
              tabAlignment: TabAlignment.start,
              labelPadding: EdgeInsets.fromLTRB(15, 0, 10, 5),
              indicator: UnderlineTabIndicator(
                borderSide: BorderSide(color: Color(0xff1fcfbb), width: 3),
                insets: EdgeInsets.only(bottom: 10),
              ),
              tabs: tabs.map<Tab>(
                (CommonTabTitle tab) {
                  return Tab(
                    text: tab.labelName,
                  );
                },
              ).toList(),
            ),
          ),
          Flexible(
              child: TabBarView(controller: _controller, children: _tabPages)),
        ],
      ),
    );
  }
}
